import requests


class TestTpshopLogin(object):
    def test01_login_success(self):
        session = requests.session()
        session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        login_url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_header = {"Content-Type": "application/x-www-form-urlencoded"}
        login_data = {"username": "13012345678", "password": "123456", "verify_code": "8888"}
        resp_login = session.post(
            url=login_url, headers=login_header, data=login_data)
        print(resp_login)
        assert resp_login.status_code == 200
        assert resp_login.json()["status"] == 1
        assert resp_login.json()["msg"] == '登陆成功'

    def test02_username_error(self):
        session = requests.session()
        session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        login_url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_header = {"Content-Type": "application/x-www-form-urlencoded"}
        login_data = {"username": "", "password": "123456", "verify_code": "8888"}
        resp_login = session.post(
            url=login_url, headers=login_header, data=login_data)
        print(resp_login)
        assert resp_login.status_code == 200
        assert resp_login.json()["status"] == -2
        assert resp_login.json()["msg"] == '密码错误!'

    def test03_passwd_error(self):
        session = requests.session()
        session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        login_url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_header = {"Content-Type": "application/x-www-form-urlencoded"}
        login_data = {"username": "13012345678", "password": "123455", "verify_code": "8888"}
        resp_login = session.post(
            url=login_url, headers=login_header, data=login_data)
        print(resp_login)
        assert resp_login.status_code == 200
        assert resp_login.json()["status"] == -2
        assert resp_login.json()["msg"] == '密码错误!'